﻿<template>
    <div id="app">
        <mt-header v-bind:title="title" style="background-color:#fda10e">
            <a slot="left" @click="back()">返回</a>

        </mt-header>

        <div class="mui-content">
            <form class="mui-input-group">
                <div class="mui-input-row">
                    <label>机构编码</label>
                    <input type="text" v-model="name" placeholder="请输入机构编码" style="width:180px;float:left">

                </div>




                <div class="mui-button-row">
                    <button type="button" class="mui-btn mui-btn-primary" @click="sub">搜索</button>&nbsp;&nbsp;

                </div>


            </form>
        </div>
        <div class="mui-content" v-if="show">
            <div class="title">
                选择机构
            </div>
            <ul class="mui-table-view">
                <li class="mui-table-view-cell" @click="go(list)">
                    <a class="mui-navigate-right">
                        {{list.name}}
                    </a>
                </li>

            </ul>
        </div>






    </div>
</template>

<script>
    import Bus from '../bus.js';
    import { Toast } from 'mint-ui';
    import { MessageBox } from 'mint-ui';
    export default {
        name: 'app',
        data() {
            return {
                title: "绑定老师",
                name: "",
                show: false,
                list: [],
                actions: [
                    "123", "ddd"
                ],

            }
        },
        methods:
        {

            go: function (uitem) {
                var _this = this;
                MessageBox({
                    title: '提示',
                    message: '确定绑定' + uitem.name + '吗?',
                    showCancelButton: true,
                    confirmButtonText: "确定",
                    cancelButtonText: "取消"
                }).then(action => {
                    
                    if (action == 'confirm') {
                        var userid = window.localStorage.getItem('userid');

                        var mid = uitem.id;

                        this.$api.post('wx/Index/bingteacher', {
                            "userid": userid,
                            "mid": mid
                        }, response => {
                            console.log(response.data);
                            if (response.status >= 200 && response.status < 300) {
                                var data = response.data;
                                if (data.status == 200) {
                                    Bus.$emit('val', "show")
                                    Bus.$emit('usertype', "2")
                                    Toast(data.message);
                                    window.localStorage.setItem('usertype', "2");
                                    window.localStorage.setItem('mid', data.data.mid);
                                    _this.$router.push({ name: 'home', params: {} });
                                   

                                } else {
                                    Toast(data.message);
                                }

                            } else {
                               // Toast("请求失败");
                                console.log(response.message);
                                //请求失败，response为失败信息
                            }
                        });

                    } else {



                    }

                });

            },
            sub: function () {
                var _this = this;
                var name = this.$data.name;

                this.$api.post('wx/Index/search', {
                    "name": name
                }, response => {
                    console.log(response.data);
                    if (response.status >= 200 && response.status < 300) {
                        var data = response.data;
                        if (data.status == 200) {
                            _this.$data.show = true;
                            _this.$data.list = data.data;
                            // _this.$router.push({ name: 'home', params: {} });
                        } else {
                            Toast(data.message);
                        }

                    } else {
                        Toast("请求失败");
                        console.log(response.message);
                        //请求失败，response为失败信息
                    }
                });

            },

            back: function () {

                this.$router.go(-1);
            }
        },
        created: function () {


        }
    }
</script>

<style scoped>
</style>